package practical_projects.games.submarine_war_v3;

import javax.swing.*;

public class Battleship extends Weapon {   // 战舰
    private int life;     // 生命
    public int score;       // 得分
    private int direction = 0;   // 移动方向，为-1表示左移，为1表示右移，为0表示不移动

    public Battleship() {
        super(66, 26, (World.WIDTH - 66) / 2, World.seaLevel - 26, 5);
        life = World.LIFE;
        score = 0;
    }

    public void setDirection(int direction) {
        this.direction = direction;
    }

    @Override
    public void move() {
        x += direction * speed;
        x = x < 0 ? 0 : x + width > World.WIDTH ? World.WIDTH - width : x;
        direction = 0;
    }

    @Override
    public ImageIcon getImage() {
        return Images.battleship;
    }

    @Override
    public boolean isOutBorder() {
        return false;
    }

    public void setLife(int life) {
        this.life = life;
    }

    public int getLife() {
        return life;
    }

    public void addLife(int lifeNum) {
        life += lifeNum;
    }

    public void subtractLife(int lifeNum) {
        life -= lifeNum;
    }
}
